home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Interfaces / CIncludes / ColorPicker.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-06  |  12.1 KB  |  450 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        ColorPicker.h
  3.  
  4.      Contains:    Color Picker package Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.1 in “MPW Latest” on ETO #18
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. */
  19.  
  20. #ifndef __COLORPICKER__
  21. #define __COLORPICKER__
  22.  
  23.  
  24. #ifndef __QUICKDRAW__
  25. #include <Quickdraw.h>
  26. #endif
  27. /*    #include <Types.h>                                            */
  28. /*        #include <ConditionalMacros.h>                            */
  29. /*    #include <MixedMode.h>                                        */
  30. /*    #include <QuickdrawText.h>                                    */
  31.  
  32. #ifndef __MIXEDMODE__
  33. #include <MixedMode.h>
  34. #endif
  35.  
  36. #ifndef __WINDOWS__
  37. #include <Windows.h>
  38. #endif
  39. /*    #include <Memory.h>                                            */
  40. /*    #include <Events.h>                                            */
  41. /*        #include <OSUtils.h>                                    */
  42. /*    #include <Controls.h>                                        */
  43. /*        #include <Menus.h>                                        */
  44.  
  45. #ifndef __DIALOGS__
  46. #include <Dialogs.h>
  47. #endif
  48. /*    #include <Errors.h>                                            */
  49. /*    #include <TextEdit.h>                                        */
  50.  
  51. #ifndef __CMAPPLICATION__
  52. #include <CMApplication.h>
  53. #endif
  54. /*    #include <Files.h>                                            */
  55. /*        #include <Finder.h>                                        */
  56. /*    #include <Printing.h>                                        */
  57. /*    #include <CMICCProfile.h>                                    */
  58.  
  59. #ifndef __BALLOONS__
  60. #include <Balloons.h>
  61. #endif
  62.  
  63. #ifdef __cplusplus
  64. extern "C" {
  65. #endif
  66.  
  67. #if PRAGMA_ALIGN_SUPPORTED
  68. #pragma options align=mac68k
  69. #endif
  70.  
  71. #if PRAGMA_IMPORT_SUPPORTED
  72. #pragma import on
  73. #endif
  74.  
  75.  
  76. enum {
  77. /*Maximum small fract value, as long*/
  78.     MaxSmallFract                = 0x0000FFFF
  79. };
  80.  
  81. enum {
  82.     kDefaultWidth                = 383,
  83.     kDefaultHeight                = 238
  84. };
  85.  
  86. enum PickerActions {
  87.     kDidNothing,
  88.     kColorChanged,
  89.     kOkHit,
  90.     kCancelHit,
  91.     kNewPickerChosen,
  92.     kApplItemHit
  93. };
  94.  
  95. typedef short PickerAction;
  96.  
  97.  
  98. enum ColorTypes {
  99.     kOriginalColor,
  100.     kNewColor
  101. };
  102.  
  103. typedef short ColorType;
  104.  
  105.  
  106. enum EditOperations {
  107.     kCut,
  108.     kCopy,
  109.     kPaste,
  110.     kClear,
  111.     kUndo
  112. };
  113.  
  114. typedef short EditOperation;
  115.  
  116.  
  117. enum ItemHitModifiers {
  118.     kMouseDown,
  119.     kKeyDown,
  120.     kFieldEntered,
  121.     kFieldLeft,
  122.     kCutOp,
  123.     kCopyOp,
  124.     kPasteOp,
  125.     kClearOp,
  126.     kUndoOp
  127. };
  128.  
  129. typedef short ItemModifier;
  130.  
  131.  
  132. enum DialogPlacementSpecifiers {
  133.     kAtSpecifiedOrigin,
  134.     kDeepestColorScreen,
  135.     kCenterOnMainScreen
  136. };
  137.  
  138. typedef short DialogPlacementSpec;
  139.  
  140.  
  141. enum {
  142.     DialogIsMoveable            = 1,
  143.     DialogIsModal                = 2,
  144.     CanModifyPalette            = 4,
  145.     CanAnimatePalette            = 8,
  146.     AppIsColorSyncAware            = 16,
  147.     InSystemDialog                = 32,
  148.     InApplicationDialog            = 64,
  149.     InPickerDialog                = 128,
  150.     DetachedFromChoices            = 256,
  151.     CanDoColor                    = 1,
  152.     CanDoBlackWhite                = 2,
  153.     AlwaysModifiesPalette        = 4,
  154.     MayModifyPalette            = 8,
  155.     PickerIsColorSyncAware        = 16,
  156.     CanDoSystemDialog            = 32,
  157.     CanDoApplDialog                = 64,
  158.     HasOwnDialog                = 128,
  159.     CanDetach                    = 256
  160. };
  161.  
  162. enum EventForcasters {
  163.     kNoForcast,
  164.     kMenuChoice,
  165.     kDialogAccept,
  166.     kDialogCancel,
  167.     kLeaveFocus,
  168.     kPickerSwitch,
  169.     kNormalKeyDown,
  170.     kNormalMouseDown
  171. };
  172.  
  173. typedef short EventForcaster;
  174.  
  175. /* A SmallFract value is just the fractional part of a Fixed number,
  176. which is the low order word.  SmallFracts are used to save room,
  177. and to be compatible with Quickdraw's RGBColor.  They can be
  178. assigned directly to and from INTEGERs. */
  179. /* Unsigned fraction between 0 and 1 */
  180. typedef unsigned short SmallFract;
  181.  
  182. /* For developmental simplicity in switching between the HLS and HSV
  183. models, HLS is reordered into HSL. Thus both models start with
  184. hue and saturation values; value/lightness/brightness is last. */
  185. struct HSVColor {
  186.     SmallFract                        hue;                        /*Fraction of circle, red at 0*/
  187.     SmallFract                        saturation;                    /*0-1, 0 for gray, 1 for pure color*/
  188.     SmallFract                        value;                        /*0-1, 0 for black, 1 for max intensity*/
  189. };
  190. typedef struct HSVColor HSVColor;
  191.  
  192. struct HSLColor {
  193.     SmallFract                        hue;                        /*Fraction of circle, red at 0*/
  194.     SmallFract                        saturation;                    /*0-1, 0 for gray, 1 for pure color*/
  195.     SmallFract                        lightness;                    /*0-1, 0 for black, 1 for white*/
  196. };
  197. typedef struct HSLColor HSLColor;
  198.  
  199. struct CMYColor {
  200.     SmallFract                        cyan;
  201.     SmallFract                        magenta;
  202.     SmallFract                        yellow;
  203. };
  204. typedef struct CMYColor CMYColor;
  205.  
  206. struct PMColor {
  207.     CMProfileHandle                    profile;
  208.     CMColor                            color;
  209. };
  210. typedef struct PMColor PMColor, *PMColorPtr;
  211.  
  212. typedef struct PrivatePickerRecord **picker;
  213.  
  214. struct PickerIconData {
  215.     short                            scriptCode;
  216.     short                            iconSuiteID;
  217.     ResType                            helpResType;
  218.     short                            helpResID;
  219. };
  220. typedef struct PickerIconData PickerIconData;
  221.  
  222. struct PickerInitData {
  223.     DialogPtr                        pickerDialog;
  224.     DialogPtr                        choicesDialog;
  225.     long                            flags;
  226.     picker                            yourself;
  227. };
  228. typedef struct PickerInitData PickerInitData;
  229.  
  230. struct PickerMenuItemInfo {
  231.     short                            editMenuID;
  232.     short                            cutItem;
  233.     short                            copyItem;
  234.     short                            pasteItem;
  235.     short                            clearItem;
  236.     short                            undoItem;
  237. };
  238. typedef struct PickerMenuItemInfo PickerMenuItemInfo;
  239.  
  240. struct PickerMenuState {
  241.     Boolean                            cutEnabled;
  242.     Boolean                            copyEnabled;
  243.     Boolean                            pasteEnabled;
  244.     Boolean                            clearEnabled;
  245.     Boolean                            undoEnabled;
  246.     Str255                            undoString;
  247. };
  248. typedef struct PickerMenuState PickerMenuState;
  249.  
  250. typedef pascal void (*ColorChangedProcPtr)(long userData, struct PMColor *newColor);
  251. typedef pascal Boolean (*UserEventProcPtr)(EventRecord *event);
  252.  
  253. #if GENERATINGCFM
  254. typedef UniversalProcPtr ColorChangedUPP;
  255. typedef UniversalProcPtr UserEventUPP;
  256. #else
  257. typedef ColorChangedProcPtr ColorChangedUPP;
  258. typedef UserEventProcPtr UserEventUPP;
  259. #endif
  260.  
  261. struct ColorPickerInfo {
  262.     struct PMColor                    theColor;
  263.     CMProfileHandle                    dstProfile;
  264.     long                            flags;
  265.     DialogPlacementSpec                placeWhere;
  266.     Point                            dialogOrigin;
  267.     long                            pickerType;
  268.     UserEventUPP                    eventProc;
  269.     ColorChangedUPP                    colorProc;
  270.     long                            colorProcData;
  271.     Str255                            prompt;
  272.     struct PickerMenuItemInfo        mInfo;
  273.     Boolean                            newColorChosen;
  274.     SInt8                            filler;
  275. };
  276. typedef struct ColorPickerInfo ColorPickerInfo;
  277.  
  278. struct SystemDialogInfo {
  279.     long                            flags;
  280.     long                            pickerType;
  281.     DialogPlacementSpec                placeWhere;
  282.     Point                            dialogOrigin;
  283.     struct PickerMenuItemInfo        mInfo;
  284. };
  285. typedef struct SystemDialogInfo SystemDialogInfo;
  286.  
  287. struct PickerDialogInfo {
  288.     long                            flags;
  289.     long                            pickerType;
  290.     Point                            *dialogOrigin;
  291.     struct PickerMenuItemInfo        mInfo;
  292. };
  293. typedef struct PickerDialogInfo PickerDialogInfo;
  294.  
  295. struct ApplicationDialogInfo {
  296.     long                            flags;
  297.     long                            pickerType;
  298.     DialogPtr                        theDialog;
  299.     Point                            pickerOrigin;
  300.     struct PickerMenuItemInfo        mInfo;
  301. };
  302. typedef struct ApplicationDialogInfo ApplicationDialogInfo;
  303.  
  304. struct EventData {
  305.     EventRecord                        *event;
  306.     PickerAction                    action;
  307.     short                            itemHit;
  308.     Boolean                            handled;
  309.     SInt8                            filler;
  310.     ColorChangedUPP                    colorProc;
  311.     long                            colorProcData;
  312.     EventForcaster                    forcast;
  313. };
  314. typedef struct EventData EventData;
  315.  
  316. struct EditData {
  317.     EditOperation                    theEdit;
  318.     PickerAction                    action;
  319.     Boolean                            handled;
  320.     SInt8                            filler;
  321. };
  322. typedef struct EditData EditData;
  323.  
  324. struct ItemHitData {
  325.     short                            itemHit;
  326.     ItemModifier                    iMod;
  327.     PickerAction                    action;
  328.     ColorChangedUPP                    colorProc;
  329.     long                            colorProcData;
  330.     Point                            where;
  331. };
  332. typedef struct ItemHitData ItemHitData;
  333.  
  334. struct HelpItemInfo {
  335.     long                            options;
  336.     Point                            tip;
  337.     Rect                            altRect;
  338.     short                            theProc;
  339.     short                            helpVariant;
  340.     HMMessageRecord                    helpMessage;
  341. };
  342. typedef struct HelpItemInfo HelpItemInfo;
  343.  
  344. /*    Below are the color conversion routines.*/
  345. extern pascal SmallFract Fix2SmallFract(Fixed f)
  346.  THREEWORDINLINE(0x3F3C, 0x0001, 0xA82E);
  347. extern pascal Fixed SmallFract2Fix(SmallFract s)
  348.  THREEWORDINLINE(0x3F3C, 0x0002, 0xA82E);
  349. extern pascal void CMY2RGB(const CMYColor *cColor, RGBColor *rColor)
  350.  THREEWORDINLINE(0x3F3C, 0x0003, 0xA82E);
  351. extern pascal void RGB2CMY(const RGBColor *rColor, CMYColor *cColor)
  352.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA82E);
  353. extern pascal void HSL2RGB(const HSLColor *hColor, RGBColor *rColor)
  354.  THREEWORDINLINE(0x3F3C, 0x0005, 0xA82E);
  355. extern pascal void RGB2HSL(const RGBColor *rColor, HSLColor *hColor)
  356.  THREEWORDINLINE(0x3F3C, 0x0006, 0xA82E);
  357. extern pascal void HSV2RGB(const HSVColor *hColor, RGBColor *rColor)
  358.  THREEWORDINLINE(0x3F3C, 0x0007, 0xA82E);
  359. extern pascal void RGB2HSV(const RGBColor *rColor, HSVColor *hColor)
  360.  THREEWORDINLINE(0x3F3C, 0x0008, 0xA82E);
  361. /*    Below brings up the ColorPicker 1.0 Dialog*/
  362. extern pascal Boolean GetColor(Point where, ConstStr255Param prompt, const RGBColor *inColor, RGBColor *outColor)
  363.  THREEWORDINLINE(0x3F3C, 0x0009, 0xA82E);
  364. /*    Below are the ColorPicker 2.0 routines.*/
  365. extern pascal OSErr PickColor(ColorPickerInfo *theColorInfo)
  366.  THREEWORDINLINE(0x3F3C, 0x0213, 0xA82E);
  367. extern pascal OSErr AddPickerToDialog(ApplicationDialogInfo *info, picker *thePicker)
  368.  THREEWORDINLINE(0x3F3C, 0x0414, 0xA82E);
  369. extern pascal OSErr CreateColorDialog(SystemDialogInfo *info, picker *thePicker)
  370.  THREEWORDINLINE(0x3F3C, 0x0415, 0xA82E);
  371. extern pascal OSErr CreatePickerDialog(PickerDialogInfo *info, picker *thePicker)
  372.  THREEWORDINLINE(0x3F3C, 0x0416, 0xA82E);
  373. extern pascal OSErr DisposeColorPicker(picker thePicker)
  374.  THREEWORDINLINE(0x3F3C, 0x0217, 0xA82E);
  375. extern pascal OSErr GetPickerVisibility(picker thePicker, Boolean *visible)
  376.  THREEWORDINLINE(0x3F3C, 0x0418, 0xA82E);
  377. extern pascal OSErr SetPickerVisibility(picker thePicker, short visible)
  378.  THREEWORDINLINE(0x3F3C, 0x0319, 0xA82E);
  379. extern pascal OSErr SetPickerPrompt(picker thePicker, Str255 promptString)
  380.  THREEWORDINLINE(0x3F3C, 0x041a, 0xA82E);
  381. extern pascal OSErr DoPickerEvent(picker thePicker, EventData *data)
  382.  THREEWORDINLINE(0x3F3C, 0x041b, 0xA82E);
  383. extern pascal OSErr DoPickerEdit(picker thePicker, EditData *data)
  384.  THREEWORDINLINE(0x3F3C, 0x041c, 0xA82E);
  385. extern pascal OSErr DoPickerDraw(picker thePicker)
  386.  THREEWORDINLINE(0x3F3C, 0x021d, 0xA82E);
  387. extern pascal OSErr GetPickerColor(picker thePicker, ColorType whichColor, PMColor *color)
  388.  THREEWORDINLINE(0x3F3C, 0x051e, 0xA82E);
  389. extern pascal OSErr SetPickerColor(picker thePicker, ColorType whichColor, PMColor *color)
  390.  THREEWORDINLINE(0x3F3C, 0x051f, 0xA82E);
  391. extern pascal OSErr GetPickerOrigin(picker thePicker, Point *where)
  392.  THREEWORDINLINE(0x3F3C, 0x0420, 0xA82E);
  393. extern pascal OSErr SetPickerOrigin(picker thePicker, Point where)
  394.  THREEWORDINLINE(0x3F3C, 0x0421, 0xA82E);
  395. extern pascal OSErr GetPickerProfile(picker thePicker, CMProfileHandle *profile)
  396.  THREEWORDINLINE(0x3F3C, 0x0422, 0xA82E);
  397. extern pascal OSErr SetPickerProfile(picker thePicker, CMProfileHandle profile)
  398.  THREEWORDINLINE(0x3F3C, 0x0423, 0xA82E);
  399. extern pascal OSErr GetPickerEditMenuState(picker thePicker, PickerMenuState *mState)
  400.  THREEWORDINLINE(0x3F3C, 0x0424, 0xA82E);
  401. extern pascal OSErr ExtractPickerHelpItem(picker thePicker, short itemNo, short whichState, HelpItemInfo *helpInfo)
  402.  THREEWORDINLINE(0x3F3C, 0x0625, 0xA82E);
  403. enum {
  404.     uppColorChangedProcInfo = kPascalStackBased
  405.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
  406.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(struct PMColor*))),
  407.     uppUserEventProcInfo = kPascalStackBased
  408.          | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  409.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(EventRecord*)))
  410. };
  411.  
  412. #if GENERATINGCFM
  413. #define NewColorChangedProc(userRoutine)        \
  414.         (ColorChangedUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppColorChangedProcInfo, GetCurrentArchitecture())
  415. #define NewUserEventProc(userRoutine)        \
  416.         (UserEventUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppUserEventProcInfo, GetCurrentArchitecture())
  417. #else
  418. #define NewColorChangedProc(userRoutine)        \
  419.         ((ColorChangedUPP) (userRoutine))
  420. #define NewUserEventProc(userRoutine)        \
  421.         ((UserEventUPP) (userRoutine))
  422. #endif
  423.  
  424. #if GENERATINGCFM
  425. #define CallColorChangedProc(userRoutine, userData, newColor)        \
  426.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppColorChangedProcInfo, (userData), (newColor))
  427. #define CallUserEventProc(userRoutine, event)        \
  428.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppUserEventProcInfo, (event))
  429. #else
  430. #define CallColorChangedProc(userRoutine, userData, newColor)        \
  431.         (*(userRoutine))((userData), (newColor))
  432. #define CallUserEventProc(userRoutine, event)        \
  433.         (*(userRoutine))((event))
  434. #endif
  435.  
  436.  
  437. #if PRAGMA_IMPORT_SUPPORTED
  438. #pragma import off
  439. #endif
  440.  
  441. #if PRAGMA_ALIGN_SUPPORTED
  442. #pragma options align=reset
  443. #endif
  444.  
  445. #ifdef __cplusplus
  446. }
  447. #endif
  448.  
  449. #endif /* __COLORPICKER__ */
  450.